Tie vector lifetimes to DataChunkHandle#737
Merged
Merged
Conversation
The Vector trait existed solely to enable an Any downcast back to FlatVector inside the arrow conversion helpers, and only FlatVector ever implemented it. Replace `&mut dyn Vector` with `&mut FlatVector` directly so the helpers no longer pretend to be polymorphic.
- Flat/List/Array/StructVector could outlive their DataChunkHandle and read freed memory - Add 'a + PhantomData<&'a ()> to all four vector types. DataChunkHandle accessors return FlatVector<'_> tied to &self, child accessors propagate - Replace From<duckdb_vector> with unsafe fn from_raw<'a> - Add compile_fail doctest on ListVector with the issue's reproducer - Breaking change: downstream needs FlatVector<'_> + unsafe from_raw instead of From<duckdb_vector>
5938c22 to
c8ed32c
Compare
c8ed32c to
f6ea4a4
Compare
This was referenced Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
FlatVector/ListVector/ArrayVector/StructVectorcould outlive their parentDataChunkHandleand read freed memory.This PR:
'aplusPhantomData<&'a ()>to all four vector wrappersDataChunkHandleaccessors to&selfso returned vectors cannot outlive the chunkcompile_faildoctest for theListVectorreproducer from Unsoundness:ListVectoris missing a lifetime specifier, allowing use-after-free #673from_rawcrate-privateBreaking:
FlatVector<'_>,ListVector<'_>, etc.duckdb_vectoris no longer part of the public API, raw callback code should go throughWritableVectorFixes #673